﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MacomberMapSystem.Common.Serialization;
using System.Data.Common;
using System.Data;
using MacomberMapSystem.Common.Processing;

namespace MacomberMapSystem.Common.Database
{
    /// <summary>
    /// This class holds information on a post-processor step
    /// </summary>
    public class MM_Database_Process: MM_Serializable
    {
        #region Variable declarations
        /// <summary>The type of the process</summary>
        [MM_Serializable_Target(MM_Serializable_Target.enumTargetType.FieldValue)]
        public String ProcessType;

        /// <summary>The title of our process</summary>
        [MM_Serializable_Target(MM_Serializable_Target.enumTargetType.FieldValue)]
        public String Title;

        /// <summary>The current value</summary>
        [MM_Serializable_Target(MM_Serializable_Target.enumTargetType.FieldValue)]
        public float CurrentValue;

        /// <summary>The total of our process</summary>
        [MM_Serializable_Target(MM_Serializable_Target.enumTargetType.FieldValue)]
        public float TotalValue;

        /// <summary>The model associated with the processing</summary>
        [MM_Serializable_Target(MM_Serializable_Target.enumTargetType.FieldValue)]
        public MM_Database_Model Model;

        /// <summary>When the process started</summary>
        [MM_Serializable_Target(MM_Serializable_Target.enumTargetType.FieldValue)]
        public DateTime StartTime;
        
        /// <summary>When the process ended</summary>
        [MM_Serializable_Target(MM_Serializable_Target.enumTargetType.FieldValue)]
        public DateTime EndTime;

        /// <summary>The state of our post process item</summary>
        [MM_Serializable_Target(MM_Serializable_Target.enumTargetType.FieldValue)]
        public CIM_Processor.enumProcessState State = CIM_Processor.enumProcessState.NotRun;

        /// <summary>When the last update occurred</summary>
        [MM_Serializable_Target(MM_Serializable_Target.enumTargetType.FieldValue)]
        public DateTime LastUpdate;

        /// <summary>The notes associated with our process</summary>
        [MM_Serializable_Target(MM_Serializable_Target.enumTargetType.FieldValue)]
        public String Notes;

        /// <summary>The user running the process</summary>
        [MM_Serializable_Target(MM_Serializable_Target.enumTargetType.FieldValue)]
        public MM_Database_User RunBy;


        /// <summary>The user running the process</summary>
        [MM_Serializable_Target(MM_Serializable_Target.enumTargetType.FieldValue)]
        public String SystemName;
        #endregion

        #region Initialization
        /// <summary>
        /// Initialize a new database process
        /// </summary>
        public MM_Database_Process()
            : base(null, null, null)
        { }

        /// <summary>
        /// Initialize a process from our repository
        /// </summary>
        /// <param name="dRd"></param>
        /// <param name="Repository"></param>
        public MM_Database_Process(DbDataReader dRd, MM_Repository Repository)
            : base(dRd, null, Repository)
        {
        }
        #endregion

        /// <summary>
        /// Refresh our process
        /// </summary>
        /// <param name="dRd"></param>
        /// <param name="Repository"></param>
        public void Refresh(DbDataReader dRd, MM_Repository Repository)
        {
            InitializeFromDatabase(dRd, null, Repository, this);            
        }
    }
}
